@Set Path=C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727;C:\Program Files\Microsoft Visual Studio 8\VC\bin;C:\Program Files\Microsoft Visual Studio 8\Common7\IDE;C:\Program Files\Microsoft Visual Studio 8\VC\vcpackages;%PATH%
@echo off
setlocal

tools\certmgr.exe -del -c -n SaasyLongTailCert -r localmachine -s My 
tools\certmgr.exe -del -c -n SaasyLongTailCert -r localmachine -s TrustedPeople 
tools\certmgr.exe -del -c -n StsCert -r localmachine -s My 
tools\certmgr.exe -del -c -n StsCert -r localmachine -s trustedpeople

tools\makecert.exe -a sha1 -sr LocalMachine -ss My -n CN=SaasyLongTailCert -sky exchange -pe
tools\makecert.exe -a sha1 -sr LocalMachine -ss My -n CN=StsCert -sky exchange -pe

tools\certmgr.exe -add -c -n SaasyLongTailCert -s -r localMachine My -s -r localMachine TrustedPeople
tools\certmgr.exe -add -c -n StsCert -s -r localMachine My -s -r localMachine TrustedPeople

for /F "delims=" %%i in ('"tools\CertificateStore_FindPrivateKey.exe" My LocalMachine -n CN^=SaasyLongTailCert -a') do set PRIVATE_KEY_FILE=%%i
echo %PRIVATE_KEY_FILE%
set WP_ACCOUNT=NT AUTHORITY\NETWORK SERVICE
(ver | findstr /C:"5.1") && set WP_ACCOUNT=%COMPUTERNAME%\ASPNET
echo Y|cacls.exe "%PRIVATE_KEY_FILE%" /E /G "%WP_ACCOUNT%":R

for /F "delims=" %%i in ('"tools\CertificateStore_FindPrivateKey.exe" My LocalMachine -n CN^=StsCert -a') do set PRIVATE_KEY_FILE=%%i
echo %PRIVATE_KEY_FILE%
set WP_ACCOUNT=NT AUTHORITY\NETWORK SERVICE
(ver | findstr /C:"5.1") && set WP_ACCOUNT=%COMPUTERNAME%\ASPNET
echo Y|cacls.exe "%PRIVATE_KEY_FILE%" /E /G "%WP_ACCOUNT%":R